<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="12">
            <a-form-item label="订单编号">
              <a-input placeholder="请输入订单编号" v-model="queryParam.ordersn"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="订单状态">
              <a-select v-model="queryParam.orderStatus" placeholder="请选择订单状态">
                <a-select-option value="1">待付款</a-select-option>
                <a-select-option value="2">待发货</a-select-option>
                <a-select-option value="3">已发货</a-select-option>
                <a-select-option value="4">已完成</a-select-option>
                <a-select-option value="5">申请退款中</a-select-option>
                <a-select-option value="6">退款成功</a-select-option>
                <a-select-option value="7">已取消</a-select-option>
                <a-select-option value="8">申请售后</a-select-option>
                <a-select-option value="9">已评论</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator" style="border-top: 5px">
      <a-button type="primary" icon="download" @click="handleExportXls('用户信息')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="user"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>

          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay" @click="handleMenuClick">
              <a-menu-item>
                <a href="javascript:;" @click="particular(record)">订单详情</a>
              </a-menu-item>

              <a-menu-item v-if="record.orderStatus==2">
                <a-popconfirm title="确定发货吗?" @confirm="() => handleFrozen(record.id,3)">
                  <a>发货</a>
                </a-popconfirm>
              </a-menu-item>

              <a-menu-item v-if="record.orderStatus==5">
                <a-popconfirm title="确定退款吗?" @confirm="() => handleFrozen(record.id,6)">
                  <a>退款</a>
                </a-popconfirm>
              </a-menu-item>

            </a-menu>
          </a-dropdown>
        </span>


      </a-table>
    </div>
    <!-- table区域-end -->

    <!--引用编辑页-->
    <order-modal ref="modalForm" @ok="modalFormOk"></order-modal>
    <!--引用详情页-->
    <order-item-modal ref="OrderItemModal"></order-item-modal>

  </a-card>
</template>

<script>
  import OrderModal from './modules/OrderModal'           //导入编辑页
  import {putAction} from '@/api/manage';
  import {shipmentOrRefund} from '@/api/api'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import OrderItemModal from "./modules/OrderItemModal";  //导入详情页

  export default {
    name: "OrderList",
    mixins: [JeecgListMixin],
    components: {
      OrderModal,
      OrderItemModal
    },
    data() {
      return {
        description: '这是订单管理页面',
        queryParam: {},
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            //表头分页
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '订单id',
            align: "left",
            dataIndex: 'id',
          },
          {
            title: '订单编号',
            align: "left",
            dataIndex: 'ordersn',
          },
          {
            title: '订单状态',
            align: "left",
            dataIndex: 'orderStatus',
          },
          {
            title: '收货地址',
            align: "left",
            dataIndex: 'address',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            width: 200,
            scopedSlots: {customRender: 'action'},
          }
        ],
        url: {
          imgerver: window._CONFIG['domianURL'] + "/sys/common/view",
          syncUser: "/process/extActProcess/doSyncUser",
          list: "/visit/ord/list",
          // deleteBatch: "/sys/user/deleteBatch",
          // exportXlsUrl: "/sys/user/exportXls",
          // importExcelUrl: "sys/user/importExcel",
        },
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      getAvatarView: function (avatar) {
        return this.url.imgerver + "/" + avatar;
      },
      //退款、发货
      handleFrozen: function (id, status) {
        let that = this;
        shipmentOrRefund({ids: id, status: status}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      //跳转详情页
      particular(record){
        this.$refs.OrderItemModal.particulars(record);
        this.$refs.OrderItemModal.title = "订单详情";
      },
    }

  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>